<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>Statistiche</title>
<meta name="description" content="" />
<meta name="keywords" content="scuola, iglesias, didattica, insegnamento, docenti, scuola media" />
<link rel="stylesheet" href="andreas08.css" type="text/css" media="screen,projection" />
<link href="../../../css/themes/default.css" rel="stylesheet" type="text/css"/>
<link href="../../../css/themes/mac_os_x.css" rel="stylesheet" type="text/css"/>
<link href="../../../css/themes/alphacube.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="../../../js/page.js"></script>
<script type="text/javascript" src="../../../js/prototype.js"></script>
<script type="text/javascript" src="../../../js/scriptaculous.js"></script>
<script type="text/javascript" src="../../../js/window.js"></script>
<script type="text/javascript" src="../../../js/window_effects.js"></script>
<script type="text/javascript">
var IE = document.all?true:false;
if (!IE) document.captureEvents(Event.MOUSEMOVE);
var stid = 0;

var tempX = 0;
var tempY = 0;

function show_menu(e, _stid){
	if (IE) { // grab the x-y pos.s if browser is IE
        tempX = event.clientX + document.body.scrollLeft;
        tempY = event.clientY + document.body.scrollTop;
    } else {  // grab the x-y pos.s if browser is NS
        tempX = e.pageX;
        tempY = e.pageY;
    }  
    // catch possible negative values in NS4
    if (tempX < 0){tempX = 0;}
    if (tempY < 0){tempY = 0;}  
    $('menu').style.top = parseInt(tempY)+"px";
    //alert(hid.style.top);
    $('menu').style.left = parseInt(tempX)+"px";
    $('menu').style.display = "inline";
    stid = _stid;
    return false;
}

function dettaglio_assenze(){
	$('menu').hide();
	//w = window.open_centered("elenco_assenze.php?alunno="+stid, "elenco", 400, 500, "");
	var w = new Window({className: "mac_os_x",  width:400, zIndex: 100, resizable: true, title: "Elenco assenze", url: "elenco_assenze.php?alunno="+stid, showEffect:Effect.Appear, hideEffect: Effect.Fade, draggable:true, wiredDrag: true});
	w.showCenter(true);
}

function delay(quadrimestre){
	$('menu').hide();
	//w = window.open_centered("dettaglio_rit_uscite.php?alunno="+stid+"&q="+quadrimestre, "el", 400, 500, "");
	var op = new Window({className: "mac_os_x",  width:400, zIndex: 100, resizable: true, title: "Elenco ritardi", url: "dettaglio_rit_uscite.php?alunno="+stid+"&q="+quadrimestre, showEffect:Effect.Appear, hideEffect: Effect.Fade, draggable:true, wiredDrag: true});
	op.showCenter(true);
}

</script>
</head>

<body>
<div id="container" >

<div id="header">
<h1><?php print $_SESSION['__config__']['intestazione_scuola'] ?></h1>
<h2>registro elettronico::statistiche</h2>
</div>

<?php include "navigation.php" ?>

<div id="content">
<form>
<table class="registro" style="width: 100%; " cellpadding="0" cellspacing="0">
<thead>
<tr>
	<td colspan="5" class="reg_header" style="text-align: center; font-weight: bold"><?php print $_SESSION['__classe__']->to_string()." - Statistiche di presenza "; if($_REQUEST['q'] == 1) print "primo quadrimestre"; else if($_REQUEST['q'] == 2) print "secondo quadrimestre"; else print "totale anno scolastico" ?></td>
</tr>
<tr>
	<td class="reg_header" style="text-align: left; font-weight: bold; padding-left: 8px">Dati complessivi</td>
	<td class="reg_header" colspan="2" style="text-align: center; font-weight: bold">Giorni di lezione: <?php print $totali['giorni'] ?> (<span style="color: red"><?php print $totali['limite_giorni'] ?></span>)</td>
	<td class="reg_header" colspan="2" style="text-align: center; font-weight: bold">Ore di lezione: <?php print $ore ?> (<span style="color: red"><?php print $ore2.":".$minuti2 ?></span>)</td>
</tr>
<tr>
	<td class="reg_header" style="width: 40%; font-weight: bold; padding-left: 8px">Alunno</td>
	<td class="reg_header" style="width: 15%; text-align: center; font-weight: bold">Assenze</td>
	<td class="reg_header" style="width: 15%; text-align: center; font-weight: bold">% assenze</td>
	<td class="reg_header" style="width: 15%; text-align: center; font-weight: bold">Ore assenza</td>
	<td class="reg_header" style="width: 15%; text-align: center; font-weight: bold">% ore assenza</td>
</tr>
</thead>
<tbody>
<?php 
$idx = 0;
while($al = $res_assenze_alunni->fetch_assoc()){
	$assenze = $totali['giorni'] - $al['giorni'];
	$perc_assenze = round((($assenze / $totali['giorni']) * 100), 2);
	/**
	 * calcolo della percentuale oraria di assenze mediante conversione
	 * dei time in secondi
	 */
	// numero totale di ore di lezione
	$tot_hours = time_to_sec($totali['ore']);
	// ore di assenza
	$abs_hours = time_to_sec($al['ore_assenza']);
	$perc_hours = round((($abs_hours / $tot_hours) * 100), 2);
	// formattazione ore assenza
	list($abs_h, $abs_m, $abs_s) = explode(":", $al['ore_assenza']);
	$ore_assenza = $abs_h.":".$abs_m;
		
	$background = "";
?>
<tr>
	<td class="<?php if($idx == 0) print("reg_firstrow"); else print("reg_row"); ?>" style="width: 35%; padding-left: 8px"><a href="#" onclick="show_menu(event, <?php print $al['id_alunno'] ?>)" style="font-weight: normal; color: inherit"><?php print $al['cognome']." ".$al['nome']?></a></td>
	<td class="<?php if($idx == 0) print("reg_firstrow"); else print("reg_row"); ?>" style="width: 15%; text-align: center"><?php print $assenze ?></td>
	<td class="<?php if($idx == 0) print("reg_firstrow"); else print("reg_row"); ?>" style="width: 15%; text-align: center;<?php if($perc_assenze > 24.99) print("border-color: black; color: red; font-weight: bold") ?>"><?php print $perc_assenze ?> %</td>
	<td class="<?php if($idx == 0) print("reg_firstrow"); else print("reg_row"); ?>" style="width: 15%; text-align: center"><?php print $ore_assenza ?></td>
	<td class="<?php if($idx == 0) print("reg_firstrow"); else print("reg_row"); ?> reg_lastcell" style="width: 15%; text-align: center;<?php if($perc_hours > 24.99) print("border-color: black; color: red; font-weight: bold") ?>"><?php print $perc_hours ?> %</td>
</tr>
</tbody>
<?php
	$idx++; 
}
?>
<tr>
	<td class="reg_header" colspan="5" style="text-align: center; border: 1px solid; font-weight: bold">
	<a href="stats.php?q=1">1 Quadrimestre</a>&nbsp;&nbsp;&nbsp;|&nbsp;&nbsp;&nbsp;<a href="stats.php?q=2">2 Quadrimestre</a>&nbsp;&nbsp;&nbsp;|&nbsp;&nbsp;&nbsp;<a href="stats.php?q=0">Totale</a>
	</td>
</tr>
</table>
</form>
<p></p>
</div>
<!-- menu contestuale -->
    <div id="menu" style="position: absolute; width: 210px; height: 50px; display: none; border: 1px solid; background-color: rgb(245,245,245); padding-left: 10px; padding-top: 10px">
    	<a style="font-weight: normal" href="#" onclick="dettaglio_assenze()">Elenco assenze</a><br />
    	<a style="font-weight: normal" href="#" onclick="delay(<?php print $q ?>)">Elenco ritardi e uscite anticipate</a><br />
    </div>
<!-- fine menu contestuale -->

<?php include "../footer.php" ?>

</div>
</body>
</html>